package com.headingdata.exercise;

public class Test5 {

    public static void main(String[] args) {
        // 数组copy
        int[] arr = {11,22,33};
        int[] arr2 = copyArray(arr);
        arr[1] = 222;
        printArray(arr2);
        printArray(arr);
    }

    public static void printArray(int[] arr){
        System.out.print("[");
        for (int i = 0; i < arr.length; i++) {
            System.out.print(i == arr.length-1 ? arr[i]:arr[i] + ",");
        }
        System.out.println("]");
    }

    public static int[] copyArray(int[] arr){
        if(arr == null){
            return arr;
        }
        int[] arr2 = new int[arr.length];
        for (int i = 0; i < arr.length; i++) {
            arr2[i] = arr[i];
        }
        return arr2;
    }
}
